package com.itheima.controller;

import com.itheima.pojo.User;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author weizhongli
 * @Date 2020/4/24
 * @Version v1.0
 * @Description
 **/
@RestController
@RequestMapping("/user")
@RefreshScope //刷新配置
public class UserController {

    @Autowired
    private UserService userService;

    @Value("${server.port}")
    private String port;

    @Value("${personName}")
    private String personName;


    //restful风格
    //@PathVariable
    //@PathVariable（“id”）
    @GetMapping("/findUserById/{id}")
    public User findUserById(@PathVariable Integer id) {

        //手动抛异常
       /* if(id==1){
            throw new RuntimeException("完蛋了 出异常了");
        }*/


        User user = userService.findUserById(id);
        user.setNote("生产者端口号:" + port + "; personName = " + personName);
       /* try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }*/
        return user;
    }
}
